home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The PC-SIG Library 10
/
The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso
/
PC_SIGCD
/
05
/
6
/
DISK0564.ZIP
/
SOURCE.ARC
/
B.ARC
/
COM.C
< prev
next >
Wrap
C/C++ Source or Header
|
1986-04-09
|
2KB
|
100 lines
/* routines to access the communications port using IBM BIOS interrupts */
/* for Aztec C86 vers. 3.20e */
/* by Jon Dart, Feb. 1986 */
#include "truth.h"
extern bios();
#define bios_int 20
#define DATAREADY 0x0100
struct regstruc {
unsigned int ax,bx,cx,dx;
};
static struct regstruc regs;
cominit(baud,parity,stop,wordlen)
/* initializes rs232 port */
/* returns rs-232 status, -1 if error */
unsigned int baud,stop,wordlen; char parity;
{
unsigned int b,p,wl;
switch(baud) {
case 110: b = 0; break;
case 150: b = 1; break;
case 300: b = 2; break;
case 600: b = 3; break;
case 1200: b= 4; break;
case 2400: b= 5; break;
case 4800: b= 6; break;
case 9600: b= 7; break;
default:
return(-1);
}
switch (wordlen) {
case 5: wl = 0; break;
case 6: wl = 1; break;
case 7: wl = 2; break;
case 8: wl = 3; break;
default: return(-1);
}
switch (parity) {
case 'N': p=0; break;
case 'E': p=3; break;
case 'O': p=1; break;
default: return(-1);
}
regs.dx = 0;
regs.ax = (b<<5) | (p<<3) | ((stop-1)<<2) | wl;
bios(bios_int,0,®s);
return(regs.ax);
}
comstatus()
/* returns rs-232 status word */
{
regs.dx = 0;
bios(bios_int,3,®s);
return(regs.ax);
}
transmit(c)
/* send c out the serial port */
/* returns status = bit 15 set if timeout */
char c;
{
unsigned int status;
while ((status = comstatus() & 0xA000)==0) ; /* wait for THR empty
or timeout*/
if ((status & 0x2000)!=0) {
regs.ax= (int) c;
regs.dx= 0;
bios(bios_int,1,®s);
return(regs.ax>>8);
}
else /* timeout */
return(status);
}
receive(c)
/* get c from the serial port */
/* returns status = TRUE if success */
char *c;
{
if (comstatus() & DATAREADY) {
regs.dx = 0;
bios(bios_int,2,®s);
*c = (regs.ax & 0xFF);
if (regs.ax>>8)
return(FALSE);
else
return(TRUE);
}
else
return(FALSE);
}